unit CommTabSheet;

{$ALIGN ON}
{$MINENUMSIZE 4}
{$WEAKPACKAGEUNIT}

interface

uses Windows, Messages;

const
  {$EXTERNALSYM WC_TABCONTROL}
  WC_TABCONTROL = 'SysTabControl32';

const
  {$EXTERNALSYM TCM_FIRST}
  TCM_FIRST               = $1300;      { Tab control messages }
  {$EXTERNALSYM CCM_FIRST}
  CCM_FIRST               = $2000;      { Common control shared messages }
  {$EXTERNALSYM CCM_SETCOLORSCHEME}
  CCM_SETCOLORSCHEME      = CCM_FIRST + 2; // lParam is color scheme
  {$EXTERNALSYM CCM_GETCOLORSCHEME}
  CCM_GETCOLORSCHEME      = CCM_FIRST + 3; // fills in COLORSCHEME pointed to by lParam
  {$EXTERNALSYM CCM_GETDROPTARGET}
  CCM_GETDROPTARGET       = CCM_FIRST + 4;
  {$EXTERNALSYM CCM_SETUNICODEFORMAT}
  CCM_SETUNICODEFORMAT    = CCM_FIRST + 5;
  {$EXTERNALSYM CCM_GETUNICODEFORMAT}
  CCM_GETUNICODEFORMAT    = CCM_FIRST + 6;
  {$EXTERNALSYM TCN_FIRST}
  TCN_FIRST                = 0-550;       { tab control }
  {$EXTERNALSYM TCN_LAST}
  TCN_LAST                 = 0-580;

const
  {$EXTERNALSYM TCS_SCROLLOPPOSITE}
  TCS_SCROLLOPPOSITE    = $0001;  // assumes multiline tab
  {$EXTERNALSYM TCS_BOTTOM}
  TCS_BOTTOM            = $0002;
  {$EXTERNALSYM TCS_RIGHT}
  TCS_RIGHT             = $0002;
  {$EXTERNALSYM TCS_MULTISELECT}
  TCS_MULTISELECT       = $0004;  // allow multi-select in button mode
  {$EXTERNALSYM TCS_FLATBUTTONS}
  TCS_FLATBUTTONS       = $0008;
  {$EXTERNALSYM TCS_FORCEICONLEFT}
  TCS_FORCEICONLEFT     = $0010;
  {$EXTERNALSYM TCS_FORCELABELLEFT}
  TCS_FORCELABELLEFT    = $0020;
  {$EXTERNALSYM TCS_HOTTRACK}
  TCS_HOTTRACK          = $0040;
  {$EXTERNALSYM TCS_VERTICAL}
  TCS_VERTICAL          = $0080;
  {$EXTERNALSYM TCS_TABS}
  TCS_TABS              = $0000;
  {$EXTERNALSYM TCS_BUTTONS}
  TCS_BUTTONS           = $0100;
  {$EXTERNALSYM TCS_SINGLELINE}
  TCS_SINGLELINE        = $0000;
  {$EXTERNALSYM TCS_MULTILINE}
  TCS_MULTILINE         = $0200;
  {$EXTERNALSYM TCS_RIGHTJUSTIFY}
  TCS_RIGHTJUSTIFY      = $0000;
  {$EXTERNALSYM TCS_FIXEDWIDTH}
  TCS_FIXEDWIDTH        = $0400;
  {$EXTERNALSYM TCS_RAGGEDRIGHT}
  TCS_RAGGEDRIGHT       = $0800;
  {$EXTERNALSYM TCS_FOCUSONBUTTONDOWN}
  TCS_FOCUSONBUTTONDOWN = $1000;
  {$EXTERNALSYM TCS_OWNERDRAWFIXED}
  TCS_OWNERDRAWFIXED    = $2000;
  {$EXTERNALSYM TCS_TOOLTIPS}
  TCS_TOOLTIPS          = $4000;
  {$EXTERNALSYM TCS_FOCUSNEVER}
  TCS_FOCUSNEVER        = $8000;

  {$EXTERNALSYM TCS_EX_FLATSEPARATORS}
  TCS_EX_FLATSEPARATORS = $00000001;
  {$EXTERNALSYM TCS_EX_REGISTERDROP}
  TCS_EX_REGISTERDROP   = $00000002;

  {$EXTERNALSYM TCM_GETIMAGELIST}
  TCM_GETIMAGELIST       = TCM_FIRST + 2;
  {$EXTERNALSYM TCM_SETIMAGELIST}
  TCM_SETIMAGELIST       = TCM_FIRST + 3;
  {$EXTERNALSYM TCM_GETITEMCOUNT}
  TCM_GETITEMCOUNT       = TCM_FIRST + 4;
  {$EXTERNALSYM TCM_DELETEITEM}
  TCM_DELETEITEM         = TCM_FIRST + 8;
  {$EXTERNALSYM TCM_DELETEALLITEMS}
  TCM_DELETEALLITEMS     = TCM_FIRST + 9;
  {$EXTERNALSYM TCM_GETITEMRECT}
  TCM_GETITEMRECT        = TCM_FIRST + 10;
  {$EXTERNALSYM TCM_GETCURSEL}
  TCM_GETCURSEL          = TCM_FIRST + 11;
  {$EXTERNALSYM TCM_SETCURSEL}
  TCM_SETCURSEL          = TCM_FIRST + 12;
  {$EXTERNALSYM TCM_HITTEST}
  TCM_HITTEST            = TCM_FIRST + 13;
  {$EXTERNALSYM TCM_SETITEMEXTRA}
  TCM_SETITEMEXTRA       = TCM_FIRST + 14;
  {$EXTERNALSYM TCM_ADJUSTRECT}
  TCM_ADJUSTRECT         = TCM_FIRST + 40;
  {$EXTERNALSYM TCM_SETITEMSIZE}
  TCM_SETITEMSIZE        = TCM_FIRST + 41;
  {$EXTERNALSYM TCM_REMOVEIMAGE}
  TCM_REMOVEIMAGE        = TCM_FIRST + 42;
  {$EXTERNALSYM TCM_SETPADDING}
  TCM_SETPADDING         = TCM_FIRST + 43;
  {$EXTERNALSYM TCM_GETROWCOUNT}
  TCM_GETROWCOUNT        = TCM_FIRST + 44;
  {$EXTERNALSYM TCM_GETTOOLTIPS}
  TCM_GETTOOLTIPS        = TCM_FIRST + 45;
  {$EXTERNALSYM TCM_SETTOOLTIPS}
  TCM_SETTOOLTIPS        = TCM_FIRST + 46;
  {$EXTERNALSYM TCM_GETCURFOCUS}
  TCM_GETCURFOCUS        = TCM_FIRST + 47;
  {$EXTERNALSYM TCM_SETCURFOCUS}
  TCM_SETCURFOCUS        = TCM_FIRST + 48;
  {$EXTERNALSYM TCM_SETMINTABWIDTH}
  TCM_SETMINTABWIDTH     = TCM_FIRST + 49;
  {$EXTERNALSYM TCM_DESELECTALL}
  TCM_DESELECTALL        = TCM_FIRST + 50;
  {$EXTERNALSYM TCM_HIGHLIGHTITEM}
  TCM_HIGHLIGHTITEM      = TCM_FIRST + 51;
  {$EXTERNALSYM TCM_SETEXTENDEDSTYLE}
  TCM_SETEXTENDEDSTYLE   = TCM_FIRST + 52;  // optional wParam == mask
  {$EXTERNALSYM TCM_GETEXTENDEDSTYLE}
  TCM_GETEXTENDEDSTYLE   = TCM_FIRST + 53;
  {$EXTERNALSYM TCM_SETUNICODEFORMAT}
  TCM_SETUNICODEFORMAT   = CCM_SETUNICODEFORMAT;
  {$EXTERNALSYM TCM_GETUNICODEFORMAT}
  TCM_GETUNICODEFORMAT   = CCM_GETUNICODEFORMAT;

  {$EXTERNALSYM TCIF_TEXT}
  TCIF_TEXT       = $0001;
  {$EXTERNALSYM TCIF_IMAGE}
  TCIF_IMAGE      = $0002;
  {$EXTERNALSYM TCIF_RTLREADING}
  TCIF_RTLREADING = $0004;
  {$EXTERNALSYM TCIF_PARAM}
  TCIF_PARAM      = $0008;
  {$EXTERNALSYM TCIF_STATE}
  TCIF_STATE      = $0010;

  {$EXTERNALSYM TCIS_BUTTONPRESSED}
  TCIS_BUTTONPRESSED      = $0001;
  {$EXTERNALSYM TCIS_HIGHLIGHTED}
  TCIS_HIGHLIGHTED        = $0002;

type
  PTCItemHeaderA = ^TTCItemHeaderA;
  PTCItemHeaderW = ^TTCItemHeaderW;
  PTCItemHeader = PTCItemHeaderA;
  {$EXTERNALSYM tagTCITEMHEADERA}
  tagTCITEMHEADERA = packed record
    mask: UINT;
    lpReserved1: UINT;
    lpReserved2: UINT;
    pszText: PAnsiChar;
    cchTextMax: Integer;
    iImage: Integer;
  end;
  {$EXTERNALSYM tagTCITEMHEADERW}
  tagTCITEMHEADERW = packed record
    mask: UINT;
    lpReserved1: UINT;
    lpReserved2: UINT;
    pszText: PWideChar;
    cchTextMax: Integer;
    iImage: Integer;
  end;
  {$EXTERNALSYM tagTCITEMHEADER}
  tagTCITEMHEADER = tagTCITEMHEADERA;
  {$EXTERNALSYM _TC_ITEMHEADERA}
  _TC_ITEMHEADERA = tagTCITEMHEADERA;
  {$EXTERNALSYM _TC_ITEMHEADERW}
  _TC_ITEMHEADERW = tagTCITEMHEADERW;
  {$EXTERNALSYM _TC_ITEMHEADER}
  _TC_ITEMHEADER = _TC_ITEMHEADERA;
  TTCItemHeaderA = tagTCITEMHEADERA;
  TTCItemHeaderW = tagTCITEMHEADERW;
  TTCItemHeader = TTCItemHeaderA;
  {$EXTERNALSYM TC_ITEMHEADERA}
  TC_ITEMHEADERA = tagTCITEMHEADERA;
  {$EXTERNALSYM TC_ITEMHEADERW}
  TC_ITEMHEADERW = tagTCITEMHEADERW;
  {$EXTERNALSYM TC_ITEMHEADER}
  TC_ITEMHEADER = TC_ITEMHEADERA;

  PTCItemA = ^TTCItemA;
  PTCItemW = ^TTCItemW;
  PTCItem = PTCItemA;
  {$EXTERNALSYM tagTCITEMA}
  tagTCITEMA = packed record
    mask: UINT;
    dwState: UINT;
    dwStateMask: UINT;
    pszText: PAnsiChar;
    cchTextMax: Integer;
    iImage: Integer;
    lParam: LPARAM;
  end;
  {$EXTERNALSYM tagTCITEMW}
  tagTCITEMW = packed record
    mask: UINT;
    dwState: UINT;
    dwStateMask: UINT;
    pszText: PWideChar;
    cchTextMax: Integer;
    iImage: Integer;
    lParam: LPARAM;
  end;
  {$EXTERNALSYM tagTCITEM}
  tagTCITEM = tagTCITEMA;
  {$EXTERNALSYM _TC_ITEMA}
  _TC_ITEMA = tagTCITEMA;
  {$EXTERNALSYM _TC_ITEMW}
  _TC_ITEMW = tagTCITEMW;
  {$EXTERNALSYM _TC_ITEM}
  _TC_ITEM = _TC_ITEMA;
  TTCItemA = tagTCITEMA;
  TTCItemW = tagTCITEMW;
  TTCItem = TTCItemA;
  {$EXTERNALSYM TC_ITEMA}
  TC_ITEMA = tagTCITEMA;
  {$EXTERNALSYM TC_ITEMW}
  TC_ITEMW = tagTCITEMW;
  {$EXTERNALSYM TC_ITEM}
  TC_ITEM = TC_ITEMA;

const
  {$EXTERNALSYM TCM_GETITEMA}
  TCM_GETITEMA             = TCM_FIRST + 5;
  {$EXTERNALSYM TCM_SETITEMA}
  TCM_SETITEMA             = TCM_FIRST + 6;
  {$EXTERNALSYM TCM_INSERTITEMA}
  TCM_INSERTITEMA          = TCM_FIRST + 7;
  {$EXTERNALSYM TCM_GETITEMW}
  TCM_GETITEMW             = TCM_FIRST + 60;
  {$EXTERNALSYM TCM_SETITEMW}
  TCM_SETITEMW             = TCM_FIRST + 61;
  {$EXTERNALSYM TCM_INSERTITEMW}
  TCM_INSERTITEMW          = TCM_FIRST + 62;

  {$EXTERNALSYM TCM_GETITEM}
  TCM_GETITEM             = TCM_GETITEMA;
  {$EXTERNALSYM TCM_SETITEM}
  TCM_SETITEM             = TCM_SETITEMA;
  {$EXTERNALSYM TCM_INSERTITEM}
  TCM_INSERTITEM          = TCM_INSERTITEMA;


const
  {$EXTERNALSYM TCHT_NOWHERE}
  TCHT_NOWHERE     = $0001;
  {$EXTERNALSYM TCHT_ONITEMICON}
  TCHT_ONITEMICON  = $0002;
  {$EXTERNALSYM TCHT_ONITEMLABEL}
  TCHT_ONITEMLABEL = $0004;
  {$EXTERNALSYM TCHT_ONITEM}
  TCHT_ONITEM      = TCHT_ONITEMICON or TCHT_ONITEMLABEL;

type
  PTCHitTestInfo = ^TTCHitTestInfo;
  {$EXTERNALSYM tagTCHITTESTINFO}
  tagTCHITTESTINFO = packed record
    pt: TPoint;
    flags: UINT;
  end;
  {$EXTERNALSYM _TC_HITTESTINFO}
  _TC_HITTESTINFO = tagTCHITTESTINFO;
  TTCHitTestInfo = tagTCHITTESTINFO;
  {$EXTERNALSYM TC_HITTESTINFO}
  TC_HITTESTINFO = tagTCHITTESTINFO;

  {$EXTERNALSYM tagTCKEYDOWN}
  tagTCKEYDOWN = packed record
    hdr: TNMHDR;
    wVKey: Word;
    flags: UINT;
  end;
  {$EXTERNALSYM _TC_KEYDOWN}
  _TC_KEYDOWN = tagTCKEYDOWN;
  TTCKeyDown = tagTCKEYDOWN;
  {$EXTERNALSYM TC_KEYDOWN}
  TC_KEYDOWN = tagTCKEYDOWN;

const
  {$EXTERNALSYM TCN_KEYDOWN}
  TCN_KEYDOWN             = TCN_FIRST - 0;
  {$EXTERNALSYM TCN_SELCHANGE}
  TCN_SELCHANGE           = TCN_FIRST - 1;
  {$EXTERNALSYM TCN_SELCHANGING}
  TCN_SELCHANGING         = TCN_FIRST - 2;
  {$EXTERNALSYM TCN_GETOBJECT}
  TCN_GETOBJECT           = TCN_FIRST - 3;

{$EXTERNALSYM TabCtrl_HitTest}
function TabCtrl_HitTest(hwndTC: HWND; pinfo: PTCHitTestInfo): Integer; inline;
{$EXTERNALSYM TabCtrl_SetItemExtra}
function TabCtrl_SetItemExtra(hwndTC: HWND; cb: Integer): BOOL; inline;
{$EXTERNALSYM TabCtrl_AdjustRect}
function TabCtrl_AdjustRect(hwnd: HWND; bLarger: BOOL; prc: PRect): Integer; inline;
{$EXTERNALSYM TabCtrl_SetItemSize}
function TabCtrl_SetItemSize(hwnd: HWND; x, y: Integer): DWORD;
{$EXTERNALSYM TabCtrl_RemoveImage}
procedure TabCtrl_RemoveImage(hwnd: HWND; i: Integer);
{$EXTERNALSYM TabCtrl_SetPadding}
procedure TabCtrl_SetPadding(hwnd: HWND; cx, cy: Integer);
{$EXTERNALSYM TabCtrl_GetRowCount}
function TabCtrl_GetRowCount(hwnd: HWND): Integer; inline;
{$EXTERNALSYM TabCtrl_GetToolTips}
function TabCtrl_GetToolTips(wnd: HWND): HWND; inline;
{$EXTERNALSYM TabCtrl_SetToolTips}
procedure TabCtrl_SetToolTips(hwnd: HWND; hwndTT: HWND);
{$EXTERNALSYM TabCtrl_GetCurFocus}
function TabCtrl_GetCurFocus(hwnd: HWND): Integer; inline;
{$EXTERNALSYM TabCtrl_SetCurFocus}
procedure TabCtrl_SetCurFocus(hwnd: HWND; i: Integer);
{$EXTERNALSYM TabCtrl_SetMinTabWidth}
function TabCtrl_SetMinTabWidth(hwnd: HWND; x: Integer): Integer; inline;
{$EXTERNALSYM TabCtrl_DeselectAll}
procedure TabCtrl_DeselectAll(hwnd: HWND; fExcludeFocus: BOOL);
{$EXTERNALSYM TabCtrl_HighlightItem}
function TabCtrl_HighlightItem(hwnd: HWND; i: Integer; fHighlight: WordBool): BOOL;
{$EXTERNALSYM TabCtrl_SetExtendedStyle}
function TabCtrl_SetExtendedStyle(hwnd: HWND; dw: DWORD): DWORD; inline;
{$EXTERNALSYM TabCtrl_GetExtendedStyle}
function TabCtrl_GetExtendedStyle(hwnd: HWND): DWORD; inline;
{$EXTERNALSYM TabCtrl_SetUnicodeFormat}
function TabCtrl_SetUnicodeFormat(hwnd: HWND; fUnicode: BOOL): BOOL; inline;
{$EXTERNALSYM TabCtrl_GetUnicodeFormat}
function TabCtrl_GetUnicodeFormat(hwnd: HWND): BOOL; inline;
{$EXTERNALSYM TabCtrl_GetItemRect}
function TabCtrl_GetItemRect(hwnd: HWND; i: Integer; var prc: TRect): BOOL; inline;

implementation

function TabCtrl_HitTest(hwndTC: HWND; pinfo: PTCHitTestInfo): Integer;
begin
  Result := SendMessage(hwndTC, TCM_HITTEST, 0, LPARAM(pinfo));
end;

function TabCtrl_SetItemExtra(hwndTC: HWND; cb: Integer): BOOL;
begin
  Result := BOOL(SendMessage(hwndTC, TCM_SETITEMEXTRA, cb, 0));
end;

function TabCtrl_AdjustRect(hwnd: HWND; bLarger: BOOL; prc: PRect): Integer;
begin
  Result := SendMessage(hwnd, TCM_ADJUSTRECT, WPARAM(bLarger), LPARAM(prc));
end;

function TabCtrl_SetItemSize(hwnd: HWND; x, y: Integer): DWORD;
begin
  Result := SendMessage(hwnd, TCM_SETITEMSIZE, 0, MAKELPARAM(x, y));
end;

procedure TabCtrl_RemoveImage(hwnd: HWND; i: Integer);
begin
  SendMessage(hwnd, TCM_REMOVEIMAGE, i, 0);
end;

procedure TabCtrl_SetPadding(hwnd: HWND; cx, cy: Integer);
begin
  SendMessage(hwnd, TCM_SETPADDING, 0, MAKELPARAM(cx, cy));
end;

function TabCtrl_GetRowCount(hwnd: HWND): Integer;
begin
  Result := SendMessage(hwnd, TCM_GETROWCOUNT, 0, 0);
end;

function TabCtrl_GetToolTips(wnd: HWND): HWND;
begin
  Result := HWND(SendMessage(wnd, TCM_GETTOOLTIPS, 0, 0));
end;

procedure TabCtrl_SetToolTips(hwnd: HWND; hwndTT: HWND);
begin
  SendMessage(hwnd, TCM_SETTOOLTIPS, WPARAM(hwndTT), 0);
end;

function TabCtrl_GetCurFocus(hwnd: HWND): Integer;
begin
  Result := SendMessage(hwnd, TCM_GETCURFOCUS, 0, 0);
end;

procedure TabCtrl_SetCurFocus(hwnd: HWND; i: Integer);
begin
  SendMessage(hwnd,TCM_SETCURFOCUS, i, 0);
end;

function TabCtrl_SetMinTabWidth(hwnd: HWND; x: Integer): Integer;
begin
  Result := SendMessage(hwnd, TCM_SETMINTABWIDTH, 0, x);
end;

procedure TabCtrl_DeselectAll(hwnd: HWND; fExcludeFocus: BOOL);
begin
  SendMessage(hwnd, TCM_DESELECTALL, WPARAM(fExcludeFocus), 0)
end;

function TabCtrl_HighlightItem(hwnd: HWND; i: Integer; fHighlight: WordBool): BOOL;
begin
  Result :=  BOOL(SendMessage(hwnd, TCM_HIGHLIGHTITEM, i, MAKELONG(Word(fHighlight), 0)));
end;

function TabCtrl_SetExtendedStyle(hwnd: HWND; dw: DWORD): DWORD;
begin
  Result := SendMessage(hwnd, TCM_SETEXTENDEDSTYLE, 0, dw);
end;

function TabCtrl_GetExtendedStyle(hwnd: HWND): DWORD;
begin
  Result := SendMessage(hwnd, TCM_GETEXTENDEDSTYLE, 0, 0);
end;

function TabCtrl_SetUnicodeFormat(hwnd: HWND; fUnicode: BOOL): BOOL;
begin
  Result := BOOL(SendMessage(hwnd, TCM_SETUNICODEFORMAT, WPARAM(fUnicode), 0));
end;

function TabCtrl_GetUnicodeFormat(hwnd: HWND): BOOL;
begin
  Result := BOOL(SendMessage(hwnd, TCM_GETUNICODEFORMAT, 0, 0));
end;

function TabCtrl_GetItemRect(hwnd: HWND; i: Integer; var prc: TRect): BOOL;
begin
  Result := BOOL(SendMessage(hwnd, TCM_GETITEMRECT, i, LPARAM(@prc)));
end;

end.
